// pages/my/my_account/index.js
const account=require("../../controllers/ControllerX").controller.account;
const accountList=require("../../controllers/ControllerX").controller.accountList;

const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    accountData1:{},
    accountData2:{},
    accountData3:{},
    select1:true,
    select2:false,
    select3:false,
    select4:true,
    select5:false,
    //收入数据
    inputAll:[],    //全部
    inputServe:[],  //服务订单
    inputGoods:[],  //商品订单
    inputCoupon:[],  //云商品订单
    inputvip:[],  //会员充值
    inputBLine:[],  //线下收入
    //支出数据
    CostAll:[], //全部
    CostDownLine:[],   //线下支出
    CostOut:[],  //提现
    CostStaff:[],  //员工结算
    CostRenew:[],  //门店续费
    inputState:true,
    outputState:false,
    //展现的数据
    selectShow:[],
    selectShow2:[],
    type1:true,
    type2:false,
    type3:false,
    type4:false,
    type5:false,
    type6:false,
    type9:false,
    type10:false,
    type11:false,
    type12:false,
    type13:false,
    value:{
      pageNumber:1,
      pageSize:20,
      genre:0,
      shopId:"",
      type:'',
      lowLine:0
    },
    stateItem:"",
    shopImg:'',
    profitMoney1:"",
    profitMoney2:"",
    profitMoney3:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      'value.shopId':wx.getStorageSync('shopId')
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getAccount();
    this.getAccountList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.pullDownGet();
  },

  /**
   * 用户点击右上角分享
   */
   // onShareAppMessage: function () {

  // },
  // 获取店铺收入支出余额数据
  getAccount(){
    var shopId=wx.getStorageSync('shopId');
    //全部收入支出
    account({shopId:shopId}).then(res=>{
      this.setData({
        accountData1:res.data,
        profitMoney1:(res.data.income-res.data.pay).toFixed(2)
      })
    })
    //线上收入支出
    account({shopId:shopId,type:0}).then(res=>{
      this.setData({
        accountData2:res.data,
        profitMoney2:(res.data.income-res.data.pay).toFixed(2)
      })
    })
    //线下收入支出
    account({shopId:shopId,type:1}).then(res=>{
      this.setData({
        accountData3:res.data,
        profitMoney3:(res.data.income-res.data.pay).toFixed(2)
      })
    })
  },
  //进行tab选择
  selectTab(event){
    let state=event.currentTarget.dataset.state;
    if(state=="0"){
      this.setData({
        select1:true,
        select2:false,
        select3:false
      })
    }else if(state=="1"){
      this.setData({
        select1:false,
        select2:true,
        select3:false
      })
    }else{
      this.setData({
        select1:false,
        select2:false,
        select3:true
      })
    }
  },
  //跳转提现记录
  jumpToInputHistory(){
    wx.navigateTo({
      url: '/pages/my/my_moneyInputHistory/index',
    })
  },
  //收入支出切换
  selectOutAndInput(event){
    let state=event.currentTarget.dataset.state;
    if(state==0){
      this.setData({
        select4:true,
        select5:false
      })
      this.setData({
        inputState:true,
        outputState:false
      })
      this.setData({
        'value.genre':0
      })
      this.setData({
        type1:true,
        type2:false,
        type3:false,
        type4:false,
        type5:false,
        type6:false,
        type9:false,
        type10:false,
        type11:false,
        type12:false,
        type13:false,
        selectShow:this.data.inputAll
      })
    }else{
      this.setData({
        select4:false,
        select5:true
      })
      this.setData({
        inputState:false,
        outputState:true
      })
      this.setData({
        'value.genre':1
      })
      this.setData({
        type1:false,
        type2:false,
        type3:false,
        type4:false,
        type5:false,
        type6:false,
        type9:true,
        type10:false,
        type11:false,
        type12:false,
        type13:false,
        selectShow2:this.data.CostAll
      })
    }
  },

  //获取第一页账单列表
  getAccountList(){
    // 获取全部收入
    let shopId=wx.getStorageSync('shopId');
    shopId=parseInt(shopId);
    accountList({shopId:shopId,genre:0,type:'',lowLine:''}).then(res=>{
      this.setData({
        inputAll:res.data.page.list,
        selectShow:res.data.page.list
      })
    })
    //获取服务订单
    accountList({shopId:shopId,genre:0,type:6,lowLine:0}).then(res=>{
      this.setData({
        inputServe:res.data.page.list,
      })
      
    })
    //获取商品订单
    accountList({shopId:shopId,genre:0,type:1,lowLine:0}).then(res=>{
      this.setData({
        inputGoods:res.data.page.list,
      })
    })
    //获取云商品订单
    accountList({shopId:shopId,genre:0,type:7,lowLine:0}).then(res=>{
      this.setData({
        inputCoupon:res.data.page.list,
      })
    })
    //获取会员充值
    accountList({shopId:shopId,genre:0,type:0,lowLine:0}).then(res=>{
      this.setData({
        inputvip:res.data.page.list,
      })
    })
    //获取线下收入
    accountList({shopId:shopId,genre:0,type:'',lowLine:1}).then(res=>{
      this.setData({
        inputBLine:res.data.page.list,
      })
      console.log(this.data.inputBLine);
    })

    //获取全部支出
    accountList({shopId:shopId,genre:1,type:'',lowLine:''}).then(res=>{
      this.setData({
        CostAll:res.data.page.list,
        shopImg:res.data.shopImg
      })
    })
    //获取提现
    accountList({shopId:shopId,genre:1,type:5,lowLine:0}).then(res=>{
      this.setData({
        CostOut:res.data.page.list,
      })
    })
    //获取线下支出
    accountList({shopId:shopId,genre:1,type:9,lowLine:1}).then(res=>{
      this.setData({
        CostDownLine:res.data.page.list,
      })
    })
    //获取员工结算
    accountList({shopId:shopId,genre:1,type:2,lowLine:0}).then(res=>{
      this.setData({
        CostStaff:res.data.page.list,
      })
    })
    //获取门店续费
    accountList({shopId:shopId,genre:1,type:8,lowLine:0}).then(res=>{
      this.setData({
        CostRenew:res.data.page.list,
      })
    })
  },

  //类型切换展现数据
  selectSeTab(e){
    let state=e.currentTarget.dataset.state;
    if(state=="0"){
      this.setData({
        type1:true,
        type2:false,
        type3:false,
        type4:false,
        type5:false,
        type6:false,
        type9:false,
        type10:false,
        type11:false,
        type12:false,
        type13:false,
        selectShow:this.data.inputAll
      })
      this.setData({
        'value.genre':0,
        'value.type':'',
        'value.lowLine':''
      })
      this.setData({
        stateItem:0
      })
    }else if(state=="1"){
      this.setData({
        type1:false,
        type2:true,
        type3:false,
        type4:false,
        type5:false,
        type6:false,
        type9:false,
        type10:false,
        type11:false,
        type12:false,
        type13:false,
        selectShow:this.data.inputServe
      })
      this.setData({
        'value.genre':0,
        'value.type':6,
        'value.lowLine':0
      })
      this.setData({
        stateItem:1
      })
    }else if(state=="2"){
      this.setData({
        type1:false,
        type2:false,
        type3:true,
        type4:false,
        type5:false,
        type6:false,
        type9:false,
        type10:false,
        type11:false,
        type12:false,
        type13:false,
        selectShow:this.data.inputGoods
      })
      this.setData({
        'value.genre':0,
        'value.type':1,
        'value.lowLine':0
      })
      this.setData({
        stateItem:2
      })
    }else if(state=="3"){
      this.setData({
        type1:false,
        type2:false,
        type3:false,
        type4:true,
        type5:false,
        type6:false,
        type9:false,
        type10:false,
        type11:false,
        type12:false,
        type13:false,
        selectShow:this.data.inputCoupon
      })
      this.setData({
        'value.genre':0,
        'value.type':7,
        'value.lowLine':0
      })
      this.setData({
        stateItem:3
      })
    }else if(state=="4"){
      this.setData({
        type1:false,
        type2:false,
        type3:false,
        type4:false,
        type5:true,
        type6:false,
        type9:false,
        type10:false,
        type11:false,
        type12:false,
        type13:false,
        selectShow:this.data.inputvip
      })
      this.setData({
        'value.genre':0,
        'value.type':0,
        'value.lowLine':0
      })
      this.setData({
        stateItem:4
      })
    }else if(state=="5"){
      this.setData({
        type1:false,
        type2:false,
        type3:false,
        type4:false,
        type5:false,
        type6:true,
        type9:false,
        type10:false,
        type11:false,
        type12:false,
        type13:false,
        selectShow:this.data.inputBLine
      })
      this.setData({
        'value.genre':0,
        'value.type':"",
        'value.lowLine':1
      })
      this.setData({
        stateItem:5
      })
    }else if(state=="8"){
      this.setData({
        type1:false,
        type2:false,
        type3:false,
        type4:false,
        type5:false,
        type6:false,
        type9:true,
        type10:false,
        type11:false,
        type12:false,
        type13:false,
        selectShow2:this.data.CostAll
      })
      this.setData({
        'value.genre':1,
        'value.type':'',
        'value.lowLine':''
      })
      this.setData({
        stateItem:8
      })
    }else if(state=="9"){
      this.setData({
        type1:false,
        type2:false,
        type3:false,
        type4:false,
        type5:false,
        type6:false,
        type9:false,
        type10:true,
        type11:false,
        type12:false,
        type13:false,
        selectShow2:this.data.CostDownLine
      })
      this.setData({
        'value.genre':1,
        'value.type':9,
        'value.lowLine':1
      })
      this.setData({
        stateItem:9
      })
    }else if(state=="10"){
      this.setData({
        type1:false,
        type2:false,
        type3:false,
        type4:false,
        type5:false,
        type6:false,
        type9:false,
        type10:false,
        type11:true,
        type12:false,
        type13:false,
        selectShow2:this.data.CostOut
      })
      this.setData({
        'value.genre':1,
        'value.type':5,
        'value.lowLine':0
      })
      this.setData({
        stateItem:10
      })
    }else if(state=="11"){
      this.setData({
        type1:false,
        type2:false,
        type3:false,
        type4:false,
        type5:false,
        type6:false,
        type9:false,
        type10:false,
        type11:false,
        type12:true,
        type13:false,
        selectShow2:this.data.CostStaff
      })
      this.setData({
        'value.genre':1,
        'value.type':2,
        'value.lowLine':0
      })
      this.setData({
        stateItem:11
      })
    }else if(state=="12"){
      this.setData({
        type1:false,
        type2:false,
        type3:false,
        type4:false,
        type5:false,
        type6:false,
        type9:false,
        type10:false,
        type11:false,
        type12:false,
        type13:true,
        selectShow2:this.data.CostRenew
      })
      this.setData({
        'value.genre':1,
        'value.type':8,
        'value.lowLine':0
      })
      this.setData({
        stateItem:12
      })
    }
  },

  //跳转提现
  jumpMoneyPut(){
    wx.navigateTo({
      url: '/pages/my/my_moneyPut/index',
    })
  },

  //下滑获取更多数据
  pullDownGet(){
    let page=this.data.value.pageNumber;
    let state=this.data.stateItem;
    page=page+1;
    this.setData({
      'value.pageNumber':page
    })
    accountList(this.data.value).then(res=>{
      let list1=res.data.page.list;
      if(state==0){
        let list2=this.data.inputAll;
        let cList=list2.concat(list1);
        this.setData({
          inputAll:cList
        })
        this.setData({
          selectShow:this.data.inputAll
        })
      }else if(state==1){
        let list2=this.data.inputServe;
        let cList=list2.concat(list1);
        this.setData({
          inputServe:cList
        })
        this.setData({
          selectShow:this.data.inputServe
        })
      }else if(state==2){
        let list2=this.data.inputGoods;
        let cList=list2.concat(list1);
        this.setData({
          inputGoods:cList
        })
        this.setData({
          selectShow:this.data.inputGoods
        })
      }else if(state==3){
        let list2=this.data.inputCoupon;
        let cList=list2.concat(list1);
        this.setData({
          inputCoupon:cList
        })
        this.setData({
          selectShow:this.data.inputCoupon
        })
      }else if(state==4){
        let list2=this.data.inputvip;
        let cList=list2.concat(list1);
        this.setData({
          inputvip:cList
        })
        this.setData({
          selectShow:this.data.inputvip
        })
      }else if(state==5){
        let list2=this.data.inputBLine;
        let cList=list2.concat(list1);
        this.setData({
          inputBLine:cList
        })
        this.setData({
          selectShow:this.data.inputBLine
        })
      }else if(state==8){
        let list2=this.data.CostAll;
        let cList=list2.concat(list1);
        this.setData({
          CostAll:cList
        })
        this.setData({
          selectShow2:this.data.CostAll
        })
      }else if(state==9){
        let list2=this.data.CostDownLine;
        let cList=list2.concat(list1);
        this.setData({
          CostDownLine:cList
        })
        this.setData({
          selectShow2:this.data.CostDownLine
        })
      }else if(state==10){
        let list2=this.data.CostOut;
        let cList=list2.concat(list1);
        this.setData({
          CostOut:cList
        })
        this.setData({
          selectShow2:this.data.CostOut
        })
      }else if(state==11){
        let list2=this.data.CostStaff;
        let cList=list2.concat(list1);
        this.setData({
          CostStaff:cList
        })
        this.setData({
          selectShow2:this.data.CostStaff
        })
      }else{
        let list2=this.data.CostRenew;
        let cList=list2.concat(list1);
        this.setData({
          CostRenew:cList
        })
        this.setData({
          selectShow2:this.data.CostRenew
        })
      }
    })
  }
})